<?php

namespace app\api\controller\web;


use app\admin\model\Devicelock;
use app\admin\model\Org;
use app\admin\model\Role;
use app\admin\model\Shopcharge;
use app\admin\model\Shopchargeconfig;
use app\admin\model\Shopdevice;
use app\admin\model\Shoporder;
use app\admin\model\Shoproom;
use app\admin\model\Shoproomset;
use app\admin\model\Shoptuan;
use app\admin\model\Shopwifi;
use app\admin\model\Tuanorder;
use app\common\controller\Api;
use OSS\OssClient;
use think\Config;

/**
 *
 */
class Room extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];


    public function getList(){

        $page = $this->request->param('page');
        $shop_id = $this->request->param('shop_id');
        $limit = 10;
        $offset = ($page - 1) * $limit;

        $user = $this->auth->getUser();
        $orgModel = new Org();
        $org = $orgModel->where('mobile',$user['mobile'])->find();

        if(!$org){
            $roleModel = new Role();
            $role = $roleModel->where('mobile',$user['mobile'])->find();
            $org = $orgModel->where('id',$role['org_id'])->find();
        }

        $where['Shop.org_id'] = $org['id'];

        if($shop_id != -1){
            $where['shop_id'] = $shop_id;
        }
        $shopRoomModel = new Shoproom();
        $list = $shopRoomModel->with(['shop'])->where($where)->limit($offset,$limit)->select();
        $total = $shopRoomModel->with(['shop'])->where($where)->count('Shoproom.id');

        foreach ($list as $key=>$val){
            $list[$key]['logo'] = cdnurl($val['logo'],true);
            $list[$key]['shop_name'] = $val['shop']['name'];
            $list[$key]['qr_code'] =  cdnurl($val['qr_code'],true);

        }

        $ret = array();
        $ret['list'] = $list;
        $ret['total'] = $total;

        $this->success('',$ret);
    }


}
